package com.xmg.day02;

public class SingleDemo {
    private static volatile SingleDemo singleDemo;

    private SingleDemo(){}

    public static SingleDemo getInstance(){

        if(singleDemo==null){
            synchronized (SingleDemo.class){
                if(singleDemo==null){
                    singleDemo = new SingleDemo();
                }
            }
        }
        return singleDemo;
    }

    public static void main(String[] args) {
        for(int i=0;i<100;i++){
            new Thread(()->{
                System.out.println(SingleDemo.getInstance().hashCode());
            },"t"+i).start();
        }
    }
}
